home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 353_02 / location.cpp < prev    next >
C/C++ Source or Header  |  1992-01-18  |  4KB  |  119 lines

  1. #include <iostream.h>
  2. #include "flyaway.h"
  3. #include "location.h"
  4. #include "items.h"
  5. #include "schedule.h"
  6.  
  7. extern location snack_bar;     // Special action in "move"
  8. extern location security;      // Special action in "move"
  9. extern items personal_items;   // Reference to players items
  10. extern schedule flight_info;
  11.  
  12.  
  13. void location::init(location *valid_north,
  14.             location *valid_east,
  15.             location *valid_south,
  16.             location *valid_west,
  17.             char *local_message,
  18.             char *local_look_message)
  19. {
  20.    north_move = valid_north;
  21.    east_move = valid_east;
  22.    south_move = valid_south;
  23.    west_move = valid_west;
  24.    message = local_message;
  25.    look_message = local_look_message;
  26. }
  27.  
  28.  
  29. location *location::move(word direction)
  30. {
  31. int no_go = FALSE;
  32.  
  33.                                       // Getting out of the snack bar
  34.    if ((this == &snack_bar) && (personal_items.item_here(money)) &&
  35.                                     (personal_items.item_here(candy)))
  36.       cout <<
  37.       "You took a candy bar and didn't pay for it.  Airport security\n"
  38.       "grabs you and after much verbal abuse agrees to let you go if\n"
  39.       "you will either return the candy bar or pay for it.\n";
  40.  
  41.                                            // Getting through security
  42.    else if ((this == &security) && (direction == north) &&
  43.                                   ((personal_items.item_here(keys)) ||
  44.                                    (personal_items.item_here(money))))
  45.       cout <<
  46.       "You cannot get through security because the beeper detects\n"
  47.       "some metallic object on you.  Many people are staring at\n"
  48.       "you and thinking that you look dangerous.\n";
  49.  
  50.                                            // A normal move somewhere
  51.    else
  52.    switch (direction) {
  53.       case north : if (north_move)
  54.                       return (north_move); // Location to north
  55.                    else
  56.                       no_go = TRUE;        // You can't go that way!
  57.                    break;
  58.       case east  : if (east_move)
  59.                       return (east_move);  // Location to east
  60.                    else
  61.                       no_go = TRUE;        // You can't go that way!
  62.                    break;
  63.       case south : if (south_move)
  64.                       return (south_move); // Location to south
  65.                    else
  66.                       no_go = TRUE;        // You can't go that way!
  67.                    break;
  68.       case west  : if (west_move)
  69.                       return (west_move);  // Location to west
  70.                    else
  71.                       no_go = TRUE;        // You can't go that way!
  72.                    break;
  73.       default    : cout << "This is not a move.\n";
  74.                    return(NULL);
  75.    }
  76.    if (no_go) cout << "Sorry, you cannot go that way!\n";
  77.    return (NULL);
  78. }
  79.  
  80.  
  81.         // This adds an item to the items object in this room
  82. void location::add_item(word item_to_add)
  83. {
  84.    list_of_items.add_item(item_to_add);
  85. }
  86.  
  87.  
  88.         // This drops an item from the list in this room
  89. void location::drop_item(word item_to_drop)
  90. {
  91.    list_of_items.drop_item(item_to_drop);
  92. }
  93.  
  94.  
  95.  
  96.          // This returns TRUE if the item is located here
  97. char location::item_here(word item_to_check)
  98. {
  99.    return (list_of_items.item_here(item_to_check));
  100. }
  101.  
  102.  
  103.         // This displays the message when the room is entered
  104.         // It also displays the flight information at a gate
  105. void location::display_message()
  106. {
  107.    cout << message;
  108. }
  109.  
  110.  
  111.         // This displays the items located in this room
  112. void location::display_list_of_items(void)
  113. {
  114.    cout << look_message;
  115.    list_of_items.list_items_in_room();
  116.    flight_info.gate_message(this);   // List the flight information
  117.                                      //  if you are at a gate
  118. }
  119.